package com.ruoyi.goods.controller;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.goods.domain.BmSpecification;
import com.ruoyi.goods.service.IBmSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品规格信息Controller
 *
 * @author ruoyi
 * @date 2023-08-09
 */
@RestController
@RequestMapping("/specification")
public class BmSpecificationController extends BaseController
{
    @Autowired
    private IBmSpecificationService bmSpecificationService;

    /**
     * 查询商品规格信息列表
     */
    @RequiresPermissions("specification:specification:list")
    @GetMapping("/list")
    public TableDataInfo list(BmSpecification bmSpecification)
    {
        startPage();
        List<BmSpecification> list = bmSpecificationService.selectBmSpecificationList(bmSpecification);
        return getDataTable(list);
    }

    /**
     * 导出商品规格信息列表
     */
    @RequiresPermissions("specification:specification:export")
    @Log(title = "商品规格信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BmSpecification bmSpecification)
    {
        List<BmSpecification> list = bmSpecificationService.selectBmSpecificationList(bmSpecification);
        ExcelUtil<BmSpecification> util = new ExcelUtil<BmSpecification>(BmSpecification.class);
        util.exportExcel(response, list, "商品规格信息数据");
    }

    /**
     * 获取商品规格信息详细信息
     */
    @RequiresPermissions("specification:specification:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bmSpecificationService.selectBmSpecificationById(id));
    }

    /**
     * 新增商品规格信息
     */
    @RequiresPermissions("specification:specification:add")
    @Log(title = "商品规格信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmSpecification bmSpecification)
    {
        return toAjax(bmSpecificationService.insertBmSpecification(bmSpecification));
    }

    /**
     * 修改商品规格信息
     */
    @RequiresPermissions("specification:specification:edit")
    @Log(title = "商品规格信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmSpecification bmSpecification)
    {
        return toAjax(bmSpecificationService.updateBmSpecification(bmSpecification));
    }

    /**
     * 删除商品规格信息
     */
    @RequiresPermissions("specification:specification:remove")
    @Log(title = "商品规格信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bmSpecificationService.deleteBmSpecificationByIds(ids));
    }
}
